package website.digitalocean.chapter13;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author: 582895699@qq.com
 * @Desctription:
 * @Date: Created in 2023/2/13 21:38
 */
public class ChatMediatorImpl implements ChatMediator {

    private List<User> users;

    public ChatMediatorImpl() {
        this.users = new ArrayList<>();
    }

    @Override
    public void sendMessage(String msg, User user) {
        for (User item : users) {
            if (item != user) {
                item.receive(msg);
            }
        }
    }

    @Override
    public void addUser(User user) {
        users.add(user);
    }
}
